from scaner.core.models import ADS
from scaner.core.config.log_config import MyLogger

main_logger = MyLogger("main")
logger = main_logger.getChild("bot_api")  # type: ignore


def combine_strings(data: list[str], max_len: int = 3500) -> list[str]:
    combined_strings = []
    current_string = ""

    for item in data:
        if len(current_string) + len(item) <= max_len:
            current_string += item
        else:
            combined_strings.append(current_string)
            current_string = item

    if current_string:
        combined_strings.append(current_string)

    return combined_strings


def prepare_ads_for_bot(data: list[ADS]) -> list[str]:
    prepared_data = []

    for item in data:
        ad_for_bot = (
            f"\n<b>{item.title}</b>\n"
            f"<i>{item.price} {item.currency}</i>\n"
            f"<a href='{item.url}'>Перейти к объявлению</a>\n"
        )
        prepared_data.append(ad_for_bot)

    return combine_strings(prepared_data)
